home *** CD-ROM | disk | FTP | other *** search
- Path: dialup-123.austin.io.com!user
- From: hamilton@shokwave.com (Jim Hamilton)
- Newsgroups: comp.lang.c++
- Subject: Re: for loop question
- Date: Tue, 30 Jan 1996 23:38:29 -0600
- Organization: Disorganized
- Message-ID: <hamilton-3001962338300001@dialup-123.austin.io.com>
- References: <4emqf8$470@opal.southwind.net>
- NNTP-Posting-Host: dialup-123.austin.io.com
- X-Newsreader: Yet Another NewsWatcher 2.0.5b5
-
- In article <4emqf8$470@opal.southwind.net>, kurtg@southwind.net (Kurt
- Graber) wrote:
-
- >I am currently learning c++ so maybe you gurus can answer this
- >also I am using borland turbo c++ 3.0
- >I can't get the following code to give me any output.
- >
- >#include <iostream.h>
- >
- >void main (void)
- >{
- > int a;
- > for(a = 0;a == 10;a++)
- > {
- > cout << "anything";
- > }
- >}
-
- The loop will exit on the first iteration because a != 10
- Remember that
-
- for(e1;e2;e3) {
- some_stuff
- }
-
- is equivalent to
-
- e1;
- while(e2) {
- some_stuff
- e3;
- }
-
- As you wrote:
-
- a = 0;
- while (a == 10) {...} // will never execute
-
- >
- >///If I change the loop to for(a=0;a<=10;a++)
- > the program will work fine.
- > why?????????
- > thanks
- > kurt
-
- --
- JFH
-
- [This .sig intentionally left blank.]
-